/*
 * @Date: 2023-03-14 17:46:56
 * @LastEditors: Chuying
 * @LastEditTime: 2023-04-03 14:06:49
 * @Description:
 */
import {
  Controller,
  Get,
  Post,
  Body,
  Req,
  Patch,
  Param,
  Delete,
  Query,
  UseGuards,
  ParseIntPipe,
} from '@nestjs/common';
import { PostingService } from './posting.service';
import { CreatePostingDto } from './dto/create-posting.dto';
import { UpdatePostingDto } from './dto/update-posting.dto';
import { Request } from 'express';
import { ApiTags } from '@nestjs/swagger';
@ApiTags('帖子')
@Controller('posting')
export class PostingController {
  constructor(private readonly postingService: PostingService) {}

  @Post('add')
  create(@Body() createPostingDto: CreatePostingDto, @Req() req: Request) {
    return this.postingService.create(createPostingDto, req.user);
  }

  @Get('list')
  findAll(
    @Query()
    query: {
      keyWord: string;
      categoryId: number;
      page: number;
      pageSize: number;
    },
  ) {
    return this.postingService.findAll(query);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.postingService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updatePostingDto: UpdatePostingDto) {
    return this.postingService.update(+id, updatePostingDto);
  }

  @Delete(':id')
  remove(@Param('id', ParseIntPipe) id: number) {
    console.log(typeof id, id);
    return this.postingService.remove(+id);
  }
}
